/*
 * jngc, Java utility classes by Nicholas Coltharp
 * Copyright (C) 2010 Nicholas Coltharp <ngc1@rice.edu>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package edu.rice.ngc1.util.io;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;

/**
 * A {@code BufferedWriter} subclass that has a few handy utility
 * methods.
 */
public class ExtendedBufferedWriter extends BufferedWriter {

    /**
     * Constructs a new {@code ExtendedWriter}.
     * 
     * @param out
     *            the {@code Writer} that this object will write to
     */
    public ExtendedBufferedWriter(Writer out) {
        super(out);
    }

    /**
     * Constructs a new {@code ExtendedWriter}.
     * 
     * @param out
     *            the {@code Writer} that this object will write to
     * @param sz
     *            the size of this object's buffer
     */
    public ExtendedBufferedWriter(Writer out, int sz) {
        super(out, sz);
    }

    /**
     * Outputs a character, followed by a line break.
     * 
     * @param c
     *            the character to write
     * @throws IOException
     *             if the underlying stream encounters an error
     */
    public void writeLine(int c) throws IOException {
        super.write(c);
        newLine();
    }

    /**
     * Outputs a set of characters, followed by a line break.
     * 
     * @param cbuf
     *            the characters to output
     * @throws IOException
     *             if the underlying stream encounters an error
     */
    public void writeLine(char[] cbuf) throws IOException {
        super.write(cbuf);
        newLine();
    }

    /**
     * Outputs a set of characters, followed by a line break.
     * 
     * @param cbuf
     *            the characters to output
     * @param off
     *            the index at which to start reading characters from
     *            {@code cbuf}
     * @param len
     *            the number of characters to output
     * @throws IOException
     *             if the underlying stream encounters an error
     */
    public void writeLine(char[] cbuf, int off, int len) throws IOException {
        super.write(cbuf, off, len);
        newLine();
    }

    /**
     * Outputs a string, followed by a line break.
     * 
     * @param str
     *            the string to output
     * @throws IOException
     *             if the underlying stream encounters an error
     */
    public void writeLine(String str) throws IOException {
        super.write(str);
        newLine();
    }

    /**
     * Outputs a set of characters from a string, followed by a line
     * break.
     * 
     * @param str
     *            the {@code String} to get characters from
     * @param off
     *            the index at which to start reading characters from
     *            {@code str}
     * @param len
     *            the number of characters to read from {@code str}
     * 
     * @throws IOException
     *             if the underlying stream encounters an error
     */
    public void writeLine(String str, int off, int len) throws IOException {
        super.write(str, off, len);
        newLine();
    }
}
